﻿using FrameworkCore.Controllers;
using FrameworkCore.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NM.Module.Auth.API.Commands.Login;
using NM.Module.Auth.API.Commands.RefreshToken;
using NM.Module.Auth.API.Commands.Register;
using NM.Module.Auth.API.DTOs;
using System.ComponentModel;

namespace NM.Module.Auth.API.Controllers;

/// <summary>
/// 登录管理
/// </summary>
[AllowAnonymous]
[Description("登录管理")]
public class AuthController : BaseModuleController
{
    /// <summary>
    /// 密码登录
    /// </summary>
    /// <returns></returns>
    [HttpPost("Login")]
    [Description("密码登录")]
    public async Task<Result<LoginOutputModel>> Login(LoginCommand command)
    {
        return await Mediator.Send(command);
    }

    /// <summary>
    /// 刷新令牌
    /// </summary>
    /// <returns></returns>
    [HttpPost("Refresh/Token")]
    [Description("刷新令牌")]
    public async Task<Result<LoginOutputModel>> RefreshToken(RefreshTokenCommand command)
    {
        return await Mediator.Send(command);
    }

    /// <summary>
    /// 注册用户
    /// </summary>
    /// <returns></returns>
    [HttpPost("Register")]
    [Description("注册用户")]
    public async Task<Result<bool>> Register(RegisterCommand command)
    {
        return await Mediator.Send(command);
    }
}
